package com.hdax.gulimall.order.web;


import com.hdax.gulimall.order.entity.OrderEntity;
import com.hdax.gulimall.order.entity.OrderItemEntity;
import com.hdax.gulimall.order.service.OrderItemService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RestController
public class haha {


    @Autowired
    private OrderItemService orderItemService;


    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/text/createOrder")
    public String createOrderTest(){
        OrderEntity orderEntity=new OrderEntity();
        orderEntity.setOrderSn(UUID.randomUUID().toString());
        //下单成功给mq发送消息
        rabbitTemplate.convertAndSend("order-event-exchange","order.create.order",orderEntity);
        return "ok";
    }

    @Transactional(propagation = Propagation.MANDATORY)
    @RequestMapping("/gaga")
    public String haha(){
        OrderItemEntity orderItemEntity=new OrderItemEntity();
        orderItemEntity.setSpuName("Dddddddddd");
        boolean save = orderItemService.save(orderItemEntity);
        System.out.println(save);

        return "dddd";
    }
}


